package com.base.cn.platform.os.service.course.agent.user;

import com.base.cn.platform.os.entity.agent.user.AgentUser;
import com.base.cn.platform.os.service.FeignAuthConfig;
import com.base.cn.platform.os.service.course.CourseBaseService;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 推广员接口
 *
 * @author LIZHIPENG
 * @since 2018/5/7
 */
@FeignClient(name= CourseBaseService.appName, configuration = FeignAuthConfig.class)
public interface AgentUserService extends CourseBaseService{

    /**
     * 判断用户是否是推广员
     * @param userId 用户
     * @return true是，false否
     */
    @RequestMapping(contextPath + "/isAgentUser")
    boolean isAgentUser(@RequestParam("userId") BigDecimal userId);

    /**
     * 查询推广员数量
     * @param params 查询条件
     * @return BigDecimal
     */
    @RequestMapping(contextPath + "/count")
    BigDecimal count(@RequestBody Map<String, Object> params);

    /**
     * 查询推广员列表（分页）
     * @param currentPage 页码
     * @param params 条件
     * @param parentData 是否设置父级推广员信息：true：是，false：否
     * @param incomeData 是否设置收益信息：true：是，false：否
     * @param userData 是否设置前台关联用户：true：是，false：否
     * @param createUserData 是否设置后台创建用户：true：是，false：否
     * @return
     */
    @RequestMapping(contextPath + "/queryAgentUserListPage")
    Map<String, Object> queryAgentUserListPage(@RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
                                               @RequestBody Map<String, Object> params,
                                               @RequestParam("parentData") boolean parentData,
                                               @RequestParam("incomeData") boolean incomeData,
                                               @RequestParam("userData") boolean userData,
                                               @RequestParam("createUserData") boolean createUserData);

    /**
     * 根据ID查询推广员
     * @param agentUserId 推广员ID
     * @param parentData 是否设置父级推广员信息：true：是，false：否
     * @param incomeData 是否设置收益信息：true：是，false：否
     * @param userData 是否设置前台关联用户：true：是，false：否
     * @param createUserData 是否设置后台创建用户：true：是，false：否
     * @return
     */
    @RequestMapping(contextPath + "/findAgentUserById")
    AgentUser findAgentUserById(@RequestParam("agentUserId") BigDecimal agentUserId,
                                @RequestParam("parentData") boolean parentData,
                                @RequestParam("incomeData") boolean incomeData,
                                @RequestParam("userData") boolean userData,
                                @RequestParam("createUserData") boolean createUserData);

    /**
     * 保存推广员
     * @param agentUser
     * @return
     */
    @RequestMapping(contextPath + "/saveAgentUser")
    Map<String, Object> saveAgentUser(@RequestBody Map<String, Object> agentUser);

    /**
     * 批量修改推广员状态
     * @param agentUserIds 推广员ID串
     * @param status 状态
     * @return
     */
    @RequestMapping(contextPath + "/updateAgentUserStatus")
    Map<String, Object> updateAgentUserStatus(@RequestParam("agentUserIds") String agentUserIds,
                                              @RequestParam("status") int status);

    /**
     * 删除推广员
     * @param agentUserId
     * @return
     */
    @RequestMapping(contextPath + "/deleteAgentUser")
    Map<String, Object> deleteAgentUser(@RequestParam("agentUserId") BigDecimal agentUserId);

    /**
     * 根据用户ID查询推广员
     * @param userId 用户ID
     * @return Map<String, Object>
     */
    @RequestMapping(contextPath + "/findAgentUserByUserId")
    Map<String, Object> findAgentUserByUserId(@RequestParam("userId") BigDecimal userId,
                                              @RequestParam(value = "incomeData", required = false, defaultValue = "false") boolean incomeData,
                                              @RequestParam(value = "invite", required = false, defaultValue = "false") boolean invite,
                                              @RequestParam(value = "hasSettlement", required = false, defaultValue = "false") boolean hasSettlement);

    /**
     * 校验用户推广员状态
     * @param userId 用户ID
     * @return Map<String, Object>
     */
    @RequestMapping(contextPath + "/checkAgentUser")
    Map<String, Object> checkAgentUser(@RequestParam("userId") BigDecimal userId);

    /**
     * 申请开通推广员
     * @param userId 用户ID
     * @param shareKey 分享Key,用于获取分享来源用户
     * @return Map<String, Object>
     */
    @RequestMapping(contextPath + "/openExtension")
    Map<String, Object> openExtension(@RequestParam("userId") BigDecimal userId,
                                      @RequestParam(value = "shareKey", required = false) String shareKey);
    /**
     * 审核推广员
     * @param agentUserId 推广员ID
     * @param flag 审核标识：true：通过，false：驳回
     * @param rejectedCause 驳回原因
     * @return Map<String, Object>
     */
    @RequestMapping(contextPath + "/aduitAgentUser")
    Map<String, Object> aduitAgentUser(@RequestParam("agentUserId") BigDecimal agentUserId,
                                       @RequestParam("flag") boolean flag,
                                       @RequestParam(value = "rejectedCause", required = false) String rejectedCause);

    /**
     * 批量导入推广员
     * @param file 文件对象
     * @return Map<String, Object>
     */
    @RequestMapping(value = contextPath + "/uploadAgentUser", method = {RequestMethod.POST}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    Map<String, Object> uploadAgentUser(@RequestPart(value = "file") MultipartFile file);

    /**
     * 查询推广员申请记录
     * @param agentUser 查询条件
     * @param parentData 是否设置上级推广员
     * @param incomeData 是否设置收益信息
     * @param userData 是否设置用户信息
     * @param createUserData 是设置创建人信息
     * @return List<AgentUser>
     */
    @RequestMapping(contextPath + "/queryAgentUserList")
    List<Map<String, Object>> queryAgentUserList(@RequestBody Map<String, Object> agentUser,
                                                 @RequestParam("parentData") boolean parentData,
                                                 @RequestParam("incomeData") boolean incomeData,
                                                 @RequestParam("userData") boolean userData,
                                                 @RequestParam("createUserData") boolean createUserData);

    /**
     * 导出推广员
     *
     * @param condition
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping(contextPath + "/downloadExcelAgentList")
    ResponseEntity<byte[]> downloadExcelAgentList(@RequestBody Map<String, Object> condition, @RequestParam("pageSize") int pageSize) throws Exception;


    /**
     * 修改平台所有推广员的结算周期
     * @return
     */
    @RequestMapping(contextPath + "/alterAgentSettType")
    Map<String, Object> alterAgentSettType(@RequestParam("settType") int settType,@RequestParam("ids") String ids);
}
